package demo.xlj.yuyi.studentapp.common;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import demo.xlj.yuyi.studentapp.R;
import demo.xlj.yuyi.studentapp.base.BaseRxActivity;
import demo.xlj.yuyi.studentapp.bean.NewBean;
import demo.xlj.yuyi.studentapp.utils.ActivityUtil;

/**
 * 社团活动 界面
 */
public class SocialActivity extends BaseRxActivity {

    @BindView(R.id.ImageView_back)
    ImageView mImageViewBack;
    @BindView(R.id.TextView_Title)
    TextView mTextViewTitle;
    @BindView(R.id.RecyclerView_Social)
    RecyclerView mRecyclerViewSocial;


    private List<NewBean> mList = new ArrayList<>();

    private BaseQuickAdapter<NewBean, BaseViewHolder> baseQuickAdapter;



    private String time[] = {
            "2018-3-12"
            , "2018-02-02"
            , "2018-02-02"
            , "2018-01-27"
            , "2018-01-25"
            , "2018-01-23"
            , "2018-01-23"
            , "2018-01-23"
            , "2018-01-23"

    };
    private String title[] = {
            "2017级8班寒假展开社会实践活动"
            , "2016级25班举办学生讲坛“财经政法大学”"
            , "2016级25班举办学生讲坛“暨南大学”"
            , "2016级25班举办学生讲坛“神奇女侠”"
            , "2017级17班举行“西方建筑史”家长讲坛活动"
            , "2017级22班举行“励志模特”班级讲坛"
            , "2017级11班举行“DC动漫”主题学生讲坛"
            , "2016级2班举行学生讲坛《影响力》"
            , "2016级2班举办学生讲坛《影视》"
    };
    private String name[] = {
            "9"
            , "1"
            , "2"
            , "3", "4", "5", "6", "7", "8"
    };


    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            if (msg.what == 1) {
                baseQuickAdapter.addData(mList);
            }
        }
    };


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_social);
        ButterKnife.bind(this);
        mTextViewTitle.setText("社团活动");
        initRecyclerView();
        initListener();

    }

    /**
     * 初始化监听
     */
    private void initListener() {

        baseQuickAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ActivityUtil.openActivityFromLeftToRightByResult(SocialActivity.this, SocialWebActivity.class, "w_game", mList.get(position).getName());
            }
        });

    }

    /**
     * 初始化RecyclerView
     */
    private void initRecyclerView() {
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(SocialActivity.this);
        mRecyclerViewSocial.setLayoutManager(layoutManager);
        baseQuickAdapter = new BaseQuickAdapter<NewBean, BaseViewHolder>(R.layout.recycler_new_item) {
            @Override
            protected void convert(BaseViewHolder helper, NewBean item) {
                helper.setText(R.id.TextView_RecyclerView_Title, item.getTitle());
                helper.setText(R.id.TextView_RecyclerView_Time, item.getTime());
            }
        };
        baseQuickAdapter.setEmptyView(R.layout.recycler_loading, mRecyclerViewSocial);
        mRecyclerViewSocial.setAdapter(baseQuickAdapter);

        NewBean newBean;
        for (int i = 0; i < name.length; i++) {
            newBean = new NewBean(name[i], title[i], time[i]);
            mList.add(newBean);
        }

        mHandler.sendEmptyMessageDelayed(1, 1000);

    }

    @OnClick(R.id.ImageView_back)
    public void onViewClicked() {
        SocialActivity.this.finish();
    }
}
